package com.yonyou.cyxdms.sysAuth.service.controller.dealerchannel;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import com.yonyou.cyxdms.sysAuth.service.dto.AscInfoDTO;
import com.yonyou.cyxdms.sysAuth.service.entity.AscInfoPO;
import com.yonyou.cyxdms.sysAuth.service.service.manage.asc.AscInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by adu on 2019/10/10.
 */
@RestController
@RequestMapping("/dealerAfterSaleInfo")
@Api(value = "经销商售后信息", tags = "经销商维护-售后相关")
public class DealerAfterSaleInfoController {
    private final Logger logger = LoggerFactory.getLogger(com.yonyou.cyxdms.sysAuth.service.controller.dealerchannel.DealerInfoController.class);

    @Autowired
    public AscInfoService ascInfoService;

    /**
     * 分页查询数据
     * adu
     *
     * @param queryCondition 查询条件AscInfoPO
     * @since 2019-10-9
     */
    @ResponseBody
    @GetMapping("/getAfterSaleInfo")
    @ApiOperation(value = "查询-售后信息维护（分页）")
    public IPage<Map<String, Object>> getSaleInfo(@RequestParam(value = "currentPage", defaultValue = "1") int currentPage,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                                  String ascCode, String ascName, String province, Integer city) {
        Page<Map<String, Object>> page = new Page(currentPage, pageSize);
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        Map<String, Object> queryCondition = new HashMap<>();
        queryCondition.put("appId", loginInfoDto.getAppId());
        queryCondition.put("ascCode", ascCode);
        queryCondition.put("ascName", ascName);
        queryCondition.put("province", province);
        queryCondition.put("city", city);
        return ascInfoService.selectPageAfterSaleInfo(page, queryCondition);
    }


    /**
     * 新增经销商售后信息
     *
     * @since 2018/10/10
     */
    @ApiOperation(value = "新增-售后信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PostMapping(value = "/insertAfterSaleInfo", produces = {"application/json;charset=UTF-8"})
    public Integer insertAfterSaleInfo(@RequestBody AscInfoPO ascinfopo) {
        return ascInfoService.insertAfterSaleInfo(ascinfopo);
    }

    @PutMapping(value = "/updateAfterSale")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "编辑-售后维护")
    public Integer update(@RequestBody AscInfoPO ascinfopo) {
        return ascInfoService.updateAfterSaleInfo(ascinfopo);
    }
}
